/*
 * Copyright Thoughtworks, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
@import "shared/common";
@import "shared/modal";
@import "shared/schmodal";
@import "shared/alert";
@import "shared/analytics-common";
@import "shared/dropdown";
@import "pipeline_configs/personalize_views_editor";
@import "pipeline_configs/dashboard_view_tabs";
@import "font-awesome-sprockets";
@import "components/horizontal-tabs";
@import "components/vertical-tabs";
@import "components/name-value";
@import "components/forms";
@import "components/buttons";

// variables

$dark-gray: #333;
$pipeline-icons-size: 16px;
$icon-color: #647984;
$icon-size: 12px;
$filter-width: 362px;
$pipeline-list-height: 265px;
$modal-header-height: 55px;
$modal-border-adj: 2px;

// ---------------------  common styles ------------------------

body {
  background: #f4f8f9;
  font-size: 14px;
}

.small-txt {
  font-size: 12px;
}

// stylelint-disable selector-id-pattern
#new_dashboard-page .reveal {
  overflow-y: visible;
}

// ---------------------  common styles end ------------------------

// animation

// building animation

%building {
  position: relative;
  background: transparent image_url("building.gif") repeat-x;
}

.dashboard {
  padding: 0 30px 50px;

  .tooltip {
    left: -100%;
    top: 90%;
    width: 10rem;
    word-wrap: break-word;

    &::before {
      left: 35%;
    }
  }
}

.page_header {
  width: 100%;
  align-items: center;
  background: #fff;
  box-shadow: 0 0 0 #000;
  height: 50px;
  box-sizing: border-box;
  border-bottom: 1px solid $border-color;
  position: fixed;
  top: 40px;
  z-index: 10;

  @include clearfix;
}

.page_title {
  font-size: 17px;
  font-weight: 600;
  margin: 12px 0 0;
  padding: 0 30px;
  align-self: center;
  float: left;
}

.dashboard-modifiers {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  position: relative;
  z-index: 5;
}

.grouping_select {
  margin: 0 0 0 10px;
  width: 145px;
  display: inline-block;
}

.pipeline-search_dashboard {
  width: 350px;
}

.dashboard-group {
  margin-bottom: 50px;
  background: #fff;
}

.main-container {
  margin-top: 50px;
  background: transparent;
  overflow: visible;
}

.dashboard-group_title {
  background: #e7eef0;
  margin: 0;
  padding: 10px 10px 10px 30px;
  position: relative;
  border-radius: $global-border-radius $global-border-radius 0 0;

  span {
    position: absolute;
    font-size: 12px;
    color: #666;
    font-weight: normal;
    top: -19px;
  }

  button {
    margin-top: -5px;
  }

  .tooltip {
    top: 120%;
  }

  .dashboard-group_add_pipeline {
    float: right;
    background: #fff;
    padding: 2px 10px;

    .icon_add {
      color: $icon-color;
      font-weight: 600;
      line-height: 25px;
    }
  }
}

.dashboard-group_name {
  font-size: 18px;
  font-weight: 600;
  line-height: 25px;
}

.dashboard-group_edit-config {
  margin-left: 5px;
}

.dashboard-group_items {
  display: flex;
  flex-wrap: wrap;
  list-style-type: none;
  margin: 0 0 0 -5px;
  padding: 20px 30px;
  border-bottom-left-radius: 3px;
  border-bottom-right-radius: 3px;

  &:empty {
    min-height: 300px;
  }
}

.dashboard-group_pipeline {
  width: 267px;
  padding: 0 0 5px;
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 5px;
  margin: 5px;
}

.new-pipeline-button {
  float: right;
  position: relative;
  z-index: 1;

  > button {
    padding: 0 35px;
  }

  .new-pipeline-items {
    position: absolute;
    right: 0;
    margin: 0;
    padding: 0;
    list-style-type: none;
    text-align: left;
    cursor: pointer;
    background: #fff;
    border: 1px solid #d6e0e2;
    border-radius: 0 0 3px 3px;
    width: 100%;

    li {
      margin: 0;
      padding: 4px 10px;
      white-space: nowrap;

      > a {
        color: #000;
      }

      &:hover {
        background: rgba(0, 0, 0, 20%);
      }
    }
  }
}

.pipeline {
  position: relative;
}

.pipeline_header {
  padding: 0 15px 10px 15px;
  margin: 10px 0 0;
  border-radius: 5px 5px 0 0;
  border-bottom: 1px solid $border-color;

  @include clearfix;
}

.pipeline_name {
  font-size: 14px;
  font-weight: 600;
  margin: 0 5px 5px 0;
  word-break: break-all;
}

.config-repo-pipeline-tooltip {
  display: block;

  div {
    display: flex;

    label {
      color: $white;
      font-size: 11px;
      font-weight: 600;
      display: inline-flex;
      line-height: normal;
    }

    span {
      display: inline-flex;
      align-self: center;
      margin-left: 5px;
      word-break: break-all;
    }
  }
}

.pipeline_sub_header {
  width: 240px;
  display: flex;
  justify-content: space-between;
}

.pipeline_actions {
  display: flex;
  position: relative;
  top: -3px;
  flex-shrink: 0;
  right: 0;
  align-items: flex-start;

  .tooltip {
    transform: translate(-53%, 15%);

    &::before {
      left: 75%;
    }
  }
}

.pipeline_history {
  text-decoration: underline;
  font-size: 13px;
  float: right;
  margin-top: 10px;
}

.material_info-error {
  margin-left: 12px;
}

.pipeline_locked {
  overflow: hidden;
  width: 25px;
  height: 25px;
  font-size: $pipeline-icons-size;
  color: $icon-color;
  cursor: pointer;
  background: none;
  margin: 0;
  padding: 0;

  @include icon-before($type: lock);

  &:focus {
    color: $icon-color;
    background: none;
  }

  &:hover {
    color: $icon-hover-color;
    background: none;
  }

  &.disabled {
    color: #999;
    cursor: not-allowed;
  }
}

.edit_config {
  overflow: hidden;
  font-size: $pipeline-icons-size;
  color: $icon-color;

  @include icon-before($type: gear);

  &:hover {
    color: $icon-hover-color;
    animation-name: rotate;
    animation-duration: 2s;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
  }

  &.disabled {
    color: #999;
    cursor: not-allowed;
  }

  @keyframes rotate {
    from {
      transform: rotate(0deg);
    }

    to {
      transform: rotate(360deg);
    }
  }
}

.pipeline-analytics {
  padding: 0;
  font-size: $pipeline-icons-size;
  color: $icon-color;
  cursor: pointer;

  @include icon-before($type: chart-bar);

  &:hover {
    color: $icon-hover-color;
  }
}

.pipeline_pause-message {
  word-break: break-all;
  font-size: 12px;
  margin: 5px 0 0;
  float: left;
  clear: both;
}

.pipeline_instance {
  padding: 10px 0 0;
  border-top: 1px dotted $border-color;
  margin: 0 15px;

  &:first-child {
    border: 0;
  }
}

.no_instance {
  margin: 25px 15px;
  font-size: 13px;
}

.pipeline_instance-label {
  @include ellipsis;

  font-size: 14px;
  font-weight: 500;
  line-height: normal;
}

.more_info {
  position: relative;

  .changes {
    position: relative;
    padding-right: 20px;

    &::after {
      content: "";
      width: 0;
      height: 0;
      border-right: 6px solid transparent;
      border-left: 6px solid transparent;
      border-top: 6px solid $dark-gray;
      position: absolute;
      top: 8px;
      left: auto;
      right: 0;
      margin: 0;
      display: inline-block;
    }
  }

  .info {
    list-style-type: none;
    margin: 5px 0;
    padding: 0;
    line-height: normal;

    li {
      display: inline-block;
      border-left: 1px solid $border-color;

      &:first-child {
        border: 0;

        a {
          padding-left: 0;
        }
      }
    }

    a {
      display: block;
      padding: 0 7px;
      font-size: 13px;
      line-height: 13px;
      text-decoration: underline;
    }
  }
}

.material_changes {
  position: absolute;
  background: $dark-gray;
  padding: 15px;
  color: #fff;
  font-size: 12px;
  width: 800px;
  z-index: 10;
  border-radius: 3px;
  max-height: 310px;
  min-height: 110px;
  overflow-y: auto;

  .revisions {
    &.changed {
      color: #ff6;
    }
  }

  .rev-head {
    border-bottom: 1px solid $border-color;
    padding: 0 0 5px;
    word-break: break-all;
  }

  .modifications {
    padding: 10px 0;
    display: flex;
    border-bottom: 1px dotted #5b5b5b;

    .item {
      width: 28%;
      box-sizing: border-box;

      &:nth-child(2) {
        padding-left: 10px;
        padding-right: 10px;
        flex-grow: 2;
      }
    }
  }

  .modified_by {
    word-break: break-all;

    span {
      @include truncate-to-lines(2);

      display: block;
    }
  }

  .revision {
    display: flex;

    .revision_id {
      display: inline-block;
      text-overflow: ellipsis;
      overflow: hidden;
      max-width: 77%;
    }
  }

  .comment {
    @include commit-message($line-count: 4);
  }
}

.pipeline_instance-details {
  font-size: 12px;
  line-height: 16px;
}

.pipeline_stages {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  list-style-type: none;
  margin: 1px 0 10px -4px;
  padding: 0;

  .manual_gate {
    padding: 1px 5px;
    cursor: pointer;

    @include icon-before(step-forward, 14px, 0);

    &.disabled {
      opacity: 0.5;
      cursor: not-allowed;

      &:hover {
        opacity: 0.5;
        cursor: not-allowed;
      }
    }
  }

  .pipeline_stage_manual_gate_wrapper {
    display: flex;
  }

  .pipeline_stage_manual_gate_wrapper .pipeline_stage {
    width: 34px;
    height: 16px;
    line-height: 13px;
    margin: 5px;
    text-align: center;

    &.passed {
      background: $passed;
      color: #fff;

      @include icon-before($passed-icon, $icon-size, 1.5px);
    }

    &.failed {
      background: $failed;
      color: #fff;

      @include icon-before($failed-icon, $icon-size, 1.5px);
    }

    &.failing {
      @extend %building;

      background: $failed image_url("failing.gif") repeat-x 50% 50%;

      > span {
        background-color: $failed;
      }
    }

    &.building {
      @extend %building;

      background-color: $building;
    }

    &.unknown {
      border: 1px solid $border-color;
      background: #e6e3e3;
    }

    &.cancelled {
      background: $building;
      color: $dark-gray;

      @include icon-before($cancelled-icon, $icon-size, 1.5px);
    }
  }
}

.pipeline_message {
  border: 1px solid $border-color;
  background: #fff;
  font-size: 12px;
  padding: 1px 10px;
  margin-top: 5px;
  border-radius: 3px;

  p {
    margin: 0;
  }

  &.success {
    border: 1px solid #1fc75954;
    background: #1fc75929;
  }

  &.error {
    border: 1px solid #c71f1f52;
    background: #c71f1f54;
  }
}

// operations buttons

.pipeline_operations {
  list-style-type: none;
  margin: 5px 0 0;
  padding: 0;
  float: left;

  li {
    display: inline-block;
    margin-left: 5px;

    &:first-child {
      margin-left: 0;
    }
  }
}

.pipeline_btn {
  border: 1px solid $border-color;
  background: #fff;
  width: 36px;
  height: 22px;

  &:focus,
  &:active {
    outline: 0;
  }

  &:hover {
    background-color: #4d4d4d;
  }
}

.pipeline_btn.play {
  background: image_url("g9/icons/bg_sprite_pipeline_actions.png") -37px -31px no-repeat #fff;

  &:hover {
    background: image_url("g9/icons/bg_sprite_pipeline_actions.png") -37px -1px no-repeat #4d4d4d;
  }

  &.disabled {
    background: image_url("g9/icons/bg_sprite_pipeline_actions.png") -37px -31px no-repeat #fff;
    opacity: 0.5;
    cursor: not-allowed;

    &:hover {
      background: image_url("g9/icons/bg_sprite_pipeline_actions.png") -37px -31px no-repeat #fff;
      opacity: 0.5;
      cursor: not-allowed;
    }
  }
}

.pipeline_btn.play_with_options {
  background: image_url("g9/icons/bg_sprite_pipeline_actions.png") -77px -31px no-repeat #fff;

  &:hover {
    background: image_url("g9/icons/bg_sprite_pipeline_actions.png") -77px -1px no-repeat #4d4d4d;
  }

  &.disabled {
    background: image_url("g9/icons/bg_sprite_pipeline_actions.png") -77px -31px no-repeat #fff;
    opacity: 0.5;
    cursor: not-allowed;

    &:hover {
      background: image_url("g9/icons/bg_sprite_pipeline_actions.png") -77px -31px no-repeat #fff;
      opacity: 0.5;
      cursor: not-allowed;
    }
  }
}

.pipeline_btn.pause {
  background: image_url("g9/icons/bg_sprite_pipeline_actions.png") -2px -31px no-repeat #fff;

  &:hover {
    background: image_url("g9/icons/bg_sprite_pipeline_actions.png") -2px -1px no-repeat #4d4d4d;
  }

  &.disabled {
    background: image_url("g9/icons/bg_sprite_pipeline_actions.png") -2px -31px no-repeat #fff;
    opacity: 0.5;
    cursor: not-allowed;

    &:hover {
      background: image_url("g9/icons/bg_sprite_pipeline_actions.png") -2px -31px no-repeat #fff;
      opacity: 0.5;
      cursor: not-allowed;
    }
  }
}

.pipeline_btn.unpause {
  background: image_url("g9/icons/bg_sprite_pipeline_actions.png") -2px -1px no-repeat #4d4d4d;

  &:hover {
    background: image_url("g9/icons/bg_sprite_pipeline_actions.png") -2px -31px no-repeat #fff;
  }

  &.disabled {
    background: image_url("g9/icons/bg_sprite_pipeline_actions.png") -2px -1px no-repeat #4d4d4d;
    opacity: 0.5;
    cursor: not-allowed;

    &:hover {
      background: image_url("g9/icons/bg_sprite_pipeline_actions.png") -2px -1px no-repeat #4d4d4d;
      opacity: 0.5;
      cursor: not-allowed;
    }
  }
}

.pipeline_stage_manual_gate_wrapper {
  .tooltip {
    left: -60px;
    margin-top: 7px;
    width: 150px;
  }

  .tooltip::before {
    left: 68px;
  }
}

.stage_manual_gate_tooltip {
  color: #000;

  &:hover {
    color: #000;
  }
}

// trigger with options

.pipeline-trigger-with-options {
  margin: 5px 0 5px 10px;
  min-height: 200px;

  .last-run-revision .value {
    @include ellipsis;

    display: block;
  }

  .material-name,
  .latest-revision {
    @include ellipsis($width: 100%);

    width: 46%;
  }

  .name-value_pair label {
    width: 180px;
  }

  .error-icon {
    position: relative;
    top: -6px;
    right: -6px;

    @include icon-before($failed-icon, $margin: 0, $color: #bd0404);
  }
}

// material latest run
.material-for-trigger {
  padding: 0 30px;

  .name-value {
    list-style-type: none;
    width: 790px;
  }

  .value {
    width: 620px;
  }
}

.comment {
  .value {
    @include commit-message($line-count: 5);
  }
}

.environment-variables-tab-content {
  padding: 0 20px;

  .environment-variables {
    margin: 30px 0 0;

    dt {
      width: 200px;
      word-break: break-all;
      padding-right: 10px;
    }

    input {
      display: inline-block;
      width: 300px;
      margin-bottom: 5px;
    }

    .override,
    .reset {
      padding-left: 10px;
      padding-top: 5px;
    }

    .overridden-message {
      padding: 5px 10px;
      margin-bottom: 10px;
      max-width: 800px;
      background: #f5f5f5;

      label {
        font-size: 12px;
        display: inline-block;
      }

      p {
        font-size: 12px;
        font-weight: 600;
        margin-bottom: 0;
        display: inline-block;
      }
    }
  }
}

.helper {
  font-size: 13px;
  padding: 5px 10px;
  background: #555;
  color: #fff;
  display: block;
}

.commit_search {
  position: relative;
}

$commits-width: 635px;

.commits {
  position: fixed;
  width: $commits-width;
  right: 10px;
  z-index: 100;
  background: #fff;
  overflow-y: scroll;
}

.commit_info {
  list-style-type: none;
  margin: 0;
  padding: 0;
  width: $commits-width;
  border: 1px solid $border-color;

  li {
    border-bottom: 1px solid $border-color;
    display: block;
    cursor: pointer;

    &:hover {
      background: #e8fafa;

      .info {
        background: #e8fafa;
      }
    }
  }

  .info {
    display: flex;
    padding: 5px 10px;
    font-size: 12px;
    background: #f5f5f5;

    span {
      padding: 0 3px;
      white-space: nowrap;

      &::before {
        content: "";
        border-left: 1px dotted $dark-gray;
        margin-right: 10px;
      }

      &:first-child {
        padding-left: 0;

        &::before {
          border: 0;
          margin: 0;
        }
      }
    }

    .rev {
      @include ellipsis($width: 130px);

      min-width: 100px;
    }

    .committer {
      @include ellipsis;
    }

    .time {
      @include ellipsis($width: 220px);

      min-width: 220px;
    }
  }

  .commit_message {
    @include commit-message($line-count: 3);

    padding: 5px 10px;
  }
}

.search-icon {
  position: relative;
  margin-top: 3px;

  @include icon-before($type: search);

  &::before {
    position: absolute;
    left: 6px;
    top: -2px;
    color: $border-color;
    font-size: 14px;
  }
}

.material-revision-search {
  display: inline-block;
  margin-bottom: 0;
  width: 418px;
  height: 35px;
  border: 1px solid $border-color;
  border-radius: 3px;
  padding: 3px 10px 3px 30px;

  &::placeholder {
    font-size: 12px;
  }
}

.search-in-progress {
  position: absolute;
  right: -16px;
  top: 10px;

  @include animation(spin 1s linear infinite);
  @include icon-before($type: spinner, $margin: 0);

  &::before {
    @include animation(spin 1s linear infinite);

    font-size: rem-calc(15px);
  }
}

.manual-stage-trigger-body {
  margin: 14px 0 -5px 10px;
}
